<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/16
 * Time: 10:10
 */
namespace app\api\validate;
use think\Validate;

class User extends Validate{
    protected $rule = [
        'username' => 'require',
        'phone_number' => 'require|mobile',
        'code' => 'require|number|min:4',
        'type' =>["require",'in'=>'1,2'],//两种不同的验证方式
        'sex' =>['require','in'=>"0,1,2"]
    ];
    protected  $message =[
        'username' => '用户名必须',
        'phone_number.require' => '手机号码必须',
        'phone_number.mobile' => '手机号码错误',
        'code.require' =>'短信验证码必须',
        'code.number' =>'验证码必须为数字',
        'code.min' =>'验证码长度必须大于4',
        'type,require' =>'类型不能为空',
        'type,in' =>'类型数值错误',
        'sex.require'=>'性别必须',
        'sex.in' =>'性别数值错误'
    ];
    protected $scene = [ //只校验手机号码吗
        'send_code' => ['phone_number'],
        'login' => ['phone_number','code','type'],
        'update_user' =>['username','sex']
    ];
}